package com.banmao.jdbcDynamicDS.service;

import com.banmao.dynamicDS.aop.DS;
import com.banmao.dynamicDS.aop.annotation.DataSource;
import com.banmao.dynamicDS.datasource.DatasourceContextHolder;
import com.banmao.jdbcDynamicDS.dao.Table2Dao;
import com.banmao.jdbcDynamicDS.entity.Table2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
public class TableService {

    @Autowired
    private Table2Dao table2Dao;

    @DataSource(DS.DS2)
    public void table2() {
        System.out.println(DatasourceContextHolder.getDS());
        Optional<Table2> table2Optional = table2Dao.findById(1);
        table2Optional.ifPresentOrElse(table2 -> System.out.println(table2.getCode()),
                () -> System.out.println("NULL"));
    }

    @DataSource(DS.DS2)
    public void tabl1() {

    }

}
